<?php
header("content-type:text/html;charset=utf-8");
include "../public/config/config.php";
include "../public/include/funcs.php";
$link=conn($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd,$cfg_dbname,$cfg_dbchar);
$id=$_GET['id']?$_GET['id']:$_POST['pid'];
$name=select($link, "kehu_mo","id=$id");
$tname= $name[0]['tname'];
$arr=select($link, 'xiaofei',"pid=$id");
$money=select($link, 'xiaofei',"pid=$id",'sum(money)');
$sum_money=$money[0]['sum(money)'];

echo "<pre>";
//print_r($arr);
echo "</pre>";
$add_arr=$_POST;
if($add_arr){
	if($add_arr["porject"]=='' || $add_arr["money"] ==''){
		echo "<script>";
		echo "alert('消费项目和金额是必填的！');";
		echo "window.location.href='showOne.php?id=".$id."';";
		echo "</script>";
	}
	$add_arr['xftime_int']=time();
	$re=add($link, 'xiaofei', $add_arr);
	if($re){
		echo "<script>";
		echo "alert('新增成功!');";
		echo "window.location.href='showOne.php?id=".$id."';";
		echo "</script>";
	}else{
		echo "新增失败，程序出错！";
	}
}

?>
<html>
	<head>
		<meta charset="UTF-8">
		<title><?php echo $tname;?> 的消费详情</title>
		<link rel="stylesheet" type="text/css" href="../public/css/main.css"/>
	</head>
	<body>
<div class="tab">
	<h3><?php echo $tname;?> 的消费详情</h3>
	
	<table border="1" cellspacing="0" cellpadding="0">
		<tr>
			<th>编号</th>
			<th>消费项</th>
			<th>消费金额(元)</th>
			<th>备注</th>
			<th>消费时间</th>
			<th>操作</th>
		</tr>
<?php
$i=0;
foreach($arr as $v){
	$i++;
	$xf_id=$v['id'];
?>			
		<tr>
			<td><?php echo $i;?></td>
			<td><?php echo $v['porject'];?></td>
			<td><?php echo $v['money'];?></td>
			<td><?php echo $v['beizhu'];?></td>
			<td><?php echo $v['xftime'];?></td>
			<td><a href="delXf.php?id=<?php echo $id;?>&xf_id=<?php echo $xf_id;?>" onclick="if(confirm('确实要删除数据吗？')) return true;else return false;">删除 </a></td>
		</tr>
<?php
}
?>	
		<tr class="tr_hz">
			<td>合计</td>
			<td>-</td>
			<td><?php echo $sum_money;?></td>
			<td>-</td>
			<td>-</td>
			<td>-</td>
		</tr>
		<!--<tr>
			<td colspan="5">
				<a href="addXf.php?id=<?php echo $id;?>">新增消费项目</a>
			</td>
		</tr>		-->
	</table>
	<div class="frm w500">
		<form action="showOne.php" method="post">
			<input type="hidden" name="pid" value="<?php echo $id?>" />
			<table border="1" cellspacing="0" cellpadding="0">
				<tr>
					<th colspan="2"><?php echo $tname." -- 新增消费项目"?></th>
				</tr>
				<tr>
					<td>消费项目：</td>
					<td><input type="text" name="porject" id="" value="" /></td>
				</tr>
				<tr>
					<td>消费金额：</td>
					<td><input type="text" name="money" id="" value="" /></td>
				</tr>
				<tr>
					<td>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</td>
					<td><textarea name="beizhu" rows="5" cols="56"></textarea></td>
				</tr>
				<tr>
					<td colspan="2"><input class="sub" type="submit" value="提交"/></td>
				</tr>
			</table>
			
		</form>
	</div>
</div>
	</body>
</html>